﻿@using MayhemServer.Extensions;
@using Microsoft.Web.Helpers;
@model MayhemServer.Models.PackageDetails
<h1>
    Add-on Details
</h1>
<div class="module-page-header">
    @if (!Model.Package.IsDeveloperPackage())
    {
        <a class="download-button" href="@Url.RouteUrl("Download", new { id = Model.Package.Id })">
            Download</a>
    }
    <h4 class="module-name">@Model.Package.GetTitle() - @Model.Package.Version</h4>
    <span class="module-subtext">By @Model.Package.Authors</span>
</div>
<div class="content-columns">
    <div class="sidebar">
        <div class="sidebar-box">
            <h4>
                contents</h4>
            <ul>
                <li class="header">Events</li>
                @if (Model.PackageEvents.Count() > 0)
                {
                    foreach (var e in Model.PackageEvents)
                    {
                    <li>
                        <div>@e</div>
                    </li>
                    }
                }
                else
                { 
                    <li>
                        <div>
                            None</div>
                    </li>
                }
                <li class="header">Reactions</li>
                @if (Model.PackageReactions.Count() > 0)
                {
                    foreach (var r in Model.PackageReactions)
                    {
                    <li>
                        <div>@r</div>
                    </li>
                    }
                }
                else
                { 
                    <li>
                        <div>None</div>
                    </li>
                }
            </ul>
        </div>
        <div class="sidebar-box">
            <h4>
                dependencies</h4>
            <ul>
                @if (string.IsNullOrEmpty(Model.Package.Dependencies))
                {
                    <li>
                        <div>None</div>
                    </li>
                }
                else
                {
                    foreach (var dependency in Model.Package.Dependencies.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        var values = dependency.Split(':');
                        var id = values[0];
                        var version = values[1];
                    <li>
                        <div>
                            <a href="@Url.RouteUrl("Package", new { id })">@id</a> @version</div>
                    </li>
                    }
                }
            </ul>
        </div>
    </div>
    <div class="main-column">
        <div class="main-section">
            <h4>add-on details</h4>
            <p>
                <label>
                    Total Downloads:</label><span class="module-info-text">@Model.Package.DownloadCount.ToString("###,##0")</span>
                <br />
                <label>
                    Last Updated:</label><span class="module-info-text">@Model.Package.LastUpdated.ToShortDateString()</span>
                <br />
                <label>
                    Package ID:</label><span class="module-info-text">@Model.Package.Id</span>
            </p>
        </div>
        <div class="main-section">
            <h4>
                description</h4>
            <p>@Html.Raw(Model.Package.Description.Trim().Replace("\n", "<br />"))</p>
        </div>
        <div class="main-section">
            <h4>
                version history</h4>
            <table>
                <thead>
                    <tr>
                        <th>
                            Name
                        </th>
                        <th>
                            Downloads
                        </th>
                        <th>
                            Last updated
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var package in Model.History)
                    {
                        <tr>
                            <td>@package.Id @package.Version
                            </td>
                            <td>@package.VersionDownloadCount.ToString("###,##0")
                            </td>
                            <td>@package.LastUpdated.ToString("d MMM yyyy")
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
		<div class="main-section">
			<h4>
				comments
			</h4>
			<div class="fb-comments" data-href="@Request.Url" data-num-posts="10" data-width="480">
			</div>
		</div>
    </div>
</div>
